package com.sakiko.ioc_07;

import org.springframework.beans.factory.FactoryBean;

public class UserServiceFactoryBean implements FactoryBean<UserService> {
    // 赋值 给 bean对象创建构造方法
    private String name;
    private int age;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    /**
     * 返回的对象是否是单例 [默认是单例]
     * 组件对象在 ioc容器存在且唯一
     *
     * @return true (default)
     */
    @Override
    public boolean isSingleton() {
        return FactoryBean.super.isSingleton();
    }

    /**
     * 封装创建复杂对象的逻辑
     *
     * @return 对象 -> ioc
     * @throws Exception
     */
    @Override
    public UserService getObject() throws Exception {
//        UserService sakiko = new UserService("sakiko", 18);
        UserService sakiko = new UserService(name, age);
        return sakiko;
    }

    /**
     * 返回对象的类型 创建对象的类型 getObject()方法返回的对象类型
     *
     * @return type
     */
    @Override
    public Class<?> getObjectType() {
        return UserService.class;
    }
}
